package lib.bone.oss.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * @author: kindear
 */
@Data
@Entity
@Table(name = "oss_file")
@EntityListeners(AuditingEntityListener.class)
@ApiModel(value = "文件上传记录")
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class FileEntity {
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @ApiModelProperty(value = "文件ID",name = "id")
    String id;

    /**
     * 唯一编码 MD5
     */
    @ApiModelProperty(value = "唯一编码",notes = "MD5编码")
    @Column(name = "uni_code")
    String uniCode;

    /**
     * 文件存储位置
     */
    @ApiModelProperty(value = "文件存放位置",notes = "本地，阿里云，七牛云等")
    @Column(name = "file_location")
    String fileLocation;

    /**
     * 文件名称
     */
    @ApiModelProperty(value = "文件名称",notes = "")
    @Column(name = "file_name")
    String fileName;
    /**
     * 文件大小
     */
    @ApiModelProperty(value = "文件大小",notes = "以B为单位")
    @Column(name = "file_size")
    Long fileSize;

    /**
     * 文件类型
     */
    @ApiModelProperty(value = "文件类型",notes = "pdf,word,etc等")
    @Column(name = "file_type")
    String fileType;

    /**
     * 文件路径 key 用于下载
     */
    @ApiModelProperty(value = "文件路径",notes = "")
    @Column(name = "file_path",length = 256)
    String filePath;
    /**
     * 上传人ID 以字符串形式存储，方便转化
     */
    @ApiModelProperty(value = "上传人ID",notes = "")
    @Column(name = "creater_id")
    String createrId;

    @CreatedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录创建时间",name = "createdTime")
    @Column(name = "created_time")
    private Date createdTime;

    @LastModifiedDate
    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @ApiModelProperty(value = "记录更新时间",name = "updatedTime")
    @Column(name = "updated_time")
    private Date updatedTime;

}
